#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
输入：v1, v2: 两个向量
输出：v1和v2的欧式距离
"""
def GetEuclidDistance(v1, v2):
    #check whether v1 and v2 has the same length
    if(len(v1) != len(v2)):
        print("Input vectors must have the same dimentionalities.")
        return 
    sum = 0;
    for i in range(len(v1)):
        sum += (v1[i]-v2[i])**2 # sqare of (v1[i]-v2[i])
    sum = sum ** (0.5)
    return sum
    
"""
显示聚类的结果
@ClusterSet 聚类后的list
"""
def ShowClusterResult(ClusterSet):
    for s in ClusterSet:
        print("**********************")
        for c in s:
            print(c);
            
"""
@desc 获取聚类的中心点
@cluster 聚类
@return 中心点
"""
def GetClusterCenter(cluster):
    length =  len(cluster[0])
    center = [0] * length
    for i in range(length):
        for c in cluster:
            center[i] += c[i]
        center[i] = center[i]*1.0 / len(cluster)
    return tuple(center)           

"""
@desc 获取权值和属性的乘积值
@w 权值向量
@data 数据向量
@return w和data的点乘积
"""
def dotproduct(w, data):
    assert(len(w) == len(data))
    ret = 0
    for i in range(0, len(w)):
        ret = ret + w[i] * data[i]
        
    return ret

def test():
    ret = GetEuclidDistance((1,2,3),(2,3,4))
    print("The result is " + str(ret))
    return 

if __name__ == "__main__": test()
